/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld;

import java.awt.*;


/**
 *
 * @author Chris Yao
 */
public class DataReadin {

    private static final int MSEC_OF_DATA = 10 * 60 * 1000;
    private double yMin, yMax; // min and max data values (not pixels, data).

    private long xMin, xMax;
    private int indexMax;

    private String id = "";
    private boolean twoG = true;    // using 2G or 6G accelerometer range

    private long[] timeMS;          // reported latest time for each guy.

    private double[] yDataG;        // Raw data collected as it comes in
    private double[] yDataX;
    private double[] yDataY;
    private double[] yDataZ;

    private int currentXs;          // most recent position on graph.

    private boolean ignoreMsgPrinted = false;

    // make these global to keep some state about the current drawn panel
    private int left = 0;
    private int right = 0;

    private double[] vel;
    private double[] dist;

    public boolean is2G() {
        return twoG;
    }

    public void takeData (String id, long tMS, int index, double x, double y, double z, double g, boolean twoG) {
        if (tMS > MSEC_OF_DATA || index >= timeMS.length) {
            if (!ignoreMsgPrinted) {
                System.out.println("Ignoring accelerometer data: not enough memory allocated");
                ignoreMsgPrinted = true;
            }
            return;  // ignore any more data than we can display
        }
        if (index < indexMax) {
            System.out.println("Index value has decreased!!! " + index + " was " + indexMax);
        }

        this.id = id;
        this.twoG = twoG;

        indexMax = currentXs = index;
        timeMS[index] = tMS;

        yDataG[index] = g;

        yDataX[index] = x;
        yDataY[index] = y;
        yDataZ[index] = z;

        System.out.println(yDataG[index]) ;

    }

}
